//
// Created by pzw on 24-3-26.
//

#include "StdAlloc.h"

template<typename T, typename... Alloc>
void Log_vec(std::vector<T, Alloc...> vs, std::string tag, std::string vs_name) {
    using namespace std;
    cout << tag << ": " << vs_name << " = {" << endl;
    for (auto it = vs.begin(); it != vs.end(); it++) {
        cout << (*it) << endl;
    }
    cout << endl << "}" << endl;
}

template<typename T, typename... Alloc>
int StdAlloc<T, Alloc...>::alloc_summary() {
    using namespace std;
    constexpr int sz{10000};
    Arena my_arena1{new char[sz], sz};
    Arena my_arena2{new char[10 * sz], 10 * sz};

    vector<int> v0;/* 使用默认构造器 */

    vector<int, My_alloc<int>> v1{My_alloc<int>{my_arena1}};/* 在my_arena1中构造对象 */
    vector<int, My_alloc<int>> v2{My_alloc<int>{my_arena2}};/* 在my_arena2中构造对象 */
    vector<int, Simple_alloc<int>> v3;                           /* 在自由存储空间上构造对象 */

    My_alloc<complex<double>> Alloc2{my_arena2};
    Arena_vec<complex<double>> vcd{{{1, 2}, {3, 4}}, Alloc2}; /* 显式分配器 */
    Simple_vec<string> vs{"Sam Vimes", "Fred Colon", "Nobby Nobbs"};       /* 默认分配器 */
    Simple_alloc<complex<string>> simpleAlloc{};
    Simple_vec<complex<string>> vs2(
            {
                    {"Sam Vimes",  "Fred Colon"},
                    {"Sam Vimes",  "Fred Colon"},
                    {"Sam Vimes",  "Fred Colon"},
                    {"Fred Colon", "Nobby Nobbs"}
            },
            simpleAlloc); /* 显式分配器 */

    return 0;
}

template<typename T, typename... Alloc>
int StdAlloc<T, Alloc...>::std_default_alloc() {
    using namespace std;
    default_allocator<string> alloc{};
    DefAlloc_vec<string> vs{{"7", "6", "5", "4", "3", "2", "1", "0"}, alloc};
    Log_vec(vs, "std_default_alloc", "vs");
    return 0;
};


int StlAllocator_main() {
    StdAlloc<int>::alloc_summary();
    StdAlloc<int>::std_default_alloc();
    return 0;
}